package com.cango.student.algorithm.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 数组全排列
 *
 */
public class AllSort {
    List<List<Integer>> list = new ArrayList<>();
    public List<List<Integer>> permute(int[] nums) {
        allSort(nums, 0);
        return list;
    }

    public void allSort(int[] nums, int start) {
        if (start == nums.length) {
            List<Integer> list2 = new ArrayList<>();
            for (int t : nums) {
                list2.add(t);
            }
            list.add(list2);
        } else {
            for (int i = start; i < nums.length; i++) {
                swap(nums, start,i);
                allSort(nums, start+1);
                swap(nums, start,i);
            }
        }
    }

    public void swap(int[] nums, int i, int j) {
        int temp = nums[i];
        nums[i]= nums[j];
        nums[j]=temp;
    }
    public static void main(String[] args){
        int[] array=new int[]{1,2,3};
        AllSort allSort = new AllSort();
        allSort.allSort(array,0);
//        permute(array,0);
    }
}
